package ar.edu.unsam.algo3.plantasvszombies.wicket;

import ar.edu.unsam.algo3.plantasvszombies.dominio.Fila;
import ar.edu.unsam.algo3.plantasvszombies.dominio.Jardin;
import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.JardinAppModel;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.model.CompoundPropertyModel;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods;
import org.uqbar.wicket.xtend.XButton;
import org.uqbar.wicket.xtend.XListView;

/**
 * @author ?
 */
@SuppressWarnings("all")
public class HomePage extends WebPage {
  @Extension
  private WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new Function0<WicketExtensionFactoryMethods>() {
    public WicketExtensionFactoryMethods apply() {
      WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new WicketExtensionFactoryMethods();
      return _wicketExtensionFactoryMethods;
    }
  }.apply();
  
  private JardinAppModel _jardinApp;
  
  public JardinAppModel getJardinApp() {
    return this._jardinApp;
  }
  
  public void setJardinApp(final JardinAppModel jardinApp) {
    this._jardinApp = jardinApp;
  }
  
  public HomePage() {
    JardinAppModel _jardinAppModel = new JardinAppModel();
    final JardinAppModel jardinApp = _jardinAppModel;
    CompoundPropertyModel<JardinAppModel> _compoundPropertyModel = new CompoundPropertyModel<JardinAppModel>(jardinApp);
    Form<JardinAppModel> _form = new Form<JardinAppModel>("tableroForm", _compoundPropertyModel);
    final Form<JardinAppModel> jardinForm = _form;
    this.agregarDatosJuego(jardinForm);
    this.agregarAcciones(jardinForm);
    this.agregarTablaFilas(jardinForm);
    this._wicketExtensionFactoryMethods.addChild(this, jardinForm);
    jardinApp.actualizar();
  }
  
  public MarkupContainer agregarDatosJuego(final Form<JardinAppModel> form) {
    MarkupContainer _xblockexpression = null;
    {
      TextField<String> _textField = new TextField<String>("jugador");
      this._wicketExtensionFactoryMethods.addChild(form, _textField);
      Label _label = new Label("recursos");
      MarkupContainer _addChild = this._wicketExtensionFactoryMethods.addChild(form, _label);
      _xblockexpression = (_addChild);
    }
    return _xblockexpression;
  }
  
  public MarkupContainer agregarAcciones(final Form<JardinAppModel> form) {
    MarkupContainer _xblockexpression = null;
    {
      XButton _xButton = new XButton("nvaFila");
      final XButton btnNvaFila = _xButton;
      final Procedure0 _function = new Procedure0() {
        public void apply() {
        }
      };
      btnNvaFila.setOnClick(_function);
      MarkupContainer _addChild = this._wicketExtensionFactoryMethods.addChild(form, btnNvaFila);
      _xblockexpression = (_addChild);
    }
    return _xblockexpression;
  }
  
  public MarkupContainer agregarTablaFilas(final Form<JardinAppModel> form) {
    MarkupContainer _xblockexpression = null;
    {
      XListView<Fila> _xListView = new XListView<Fila>("misFilas");
      final XListView<Fila> listView = _xListView;
      final Procedure1<ListItem<Fila>> _function = new Procedure1<ListItem<Fila>>() {
        public void apply(final ListItem<Fila> item) {
          Fila _modelObject = item.getModelObject();
          CompoundPropertyModel<Fila> _asCompoundModel = HomePage.this._wicketExtensionFactoryMethods.<Fila>asCompoundModel(_modelObject);
          item.setModel(_asCompoundModel);
          Label _label = new Label("tipo");
          HomePage.this._wicketExtensionFactoryMethods.addChild(item, _label);
          Label _label_1 = new Label("plantas");
          HomePage.this._wicketExtensionFactoryMethods.addChild(item, _label_1);
          XButton _xButton = new XButton("eliminar");
          final Procedure0 _function = new Procedure0() {
            public void apply() {
              JardinAppModel _jardinApp = HomePage.this.getJardinApp();
              Jardin _jardin = _jardinApp.getJardin();
              Fila _modelObject = item.getModelObject();
              _jardin.eliminarFila(_modelObject);
            }
          };
          XButton _setOnClick = _xButton.setOnClick(_function);
          HomePage.this._wicketExtensionFactoryMethods.addChild(item, _setOnClick);
        }
      };
      listView.setPopulateItem(_function);
      MarkupContainer _addChild = this._wicketExtensionFactoryMethods.addChild(form, listView);
      _xblockexpression = (_addChild);
    }
    return _xblockexpression;
  }
}
